import { PointOptions } from '@/hooks/useCesiumPoints';

// 静态引入所有图片资源
// 名称映射资源
import menzhanMark from '@/assets/marks/menzhan-mark.png';
import menzhanHuise from '@/assets/marks/menzhan-huise.png';
import tiaoyazhanMark from '@/assets/marks/tiaoyazhan-mark.png';
import tiaoyazhanhuiseMark from '@/assets/marks/tiaoyazhanhuise-mark.png';
import tiaofengchubeiMark from '@/assets/marks/tiaofengchubei-mark.png';
import shangyeMark from '@/assets/marks/shangye-mark.png';
import gongyeMark from '@/assets/marks/gongye-mark.png';
import shigongMark from '@/assets/marks/shigong-mark.png';
import qiangxiuduiMark from '@/assets/marks/qiangxiudui-mark.png';
import concentrationMonitor from '@/assets/marks/concentration-monitor.png';
import concentrationMonitorLixian from '@/assets/marks/concentration-monitor-lixian.png';
import perimeterRestaurant from '@/assets/marks/perimeter-restaurant.png';
import perimeterRestaurantLixian from '@/assets/marks/perimeter-restaurant-lixian.png';
import videoZaixian from '@/assets/marks/video_mark.png';
import videoLixian from '@/assets/marks/video_mark-huise.png';
import paichu from '@/assets/marks/tubiao-mark.png';
import famen from '@/assets/marks/pip_famen.png';
import traffic from '@/assets/marks/traffic-control.png';
import school from '@/assets/marks/perimeter-school.png';
import conventionCenter from '@/assets/modelingMarks/会展中心.png';
import trainStation from '@/assets/modelingMarks/火车站.png';
import busStation from '@/assets/modelingMarks/汽车站.png';
import longDistanceBusStation from '@/assets/modelingMarks/长途汽车站.png';
import forestFireStreet from '@/assets/modelingMarks/森林防火重点街道.png';
import parkingLot from '@/assets/modelingMarks/停车场.png';
import library from '@/assets/modelingMarks/图书馆.png';
import culturalPalace from '@/assets/modelingMarks/文化宫.png';
import materialPoint from '@/assets/modelingMarks/物资点位.png';
import fireEquipment from '@/assets/modelingMarks/消防设备.png';
import keyFireUnit from '@/assets/modelingMarks/消防重点单位.png';
import camera from '@/assets/marks/video_mark.png';
import rescueTeam from '@/assets/marks/shiyingji.png';
// 设备分类资源
import gasWeishi from '@/assets/marks/gas_weishi.png';
import gasWeishiHuise from '@/assets/marks/gas_weishi_huise.png';
import keranqitiZaixian from '@/assets/marks/keranqiti-zaixian.png';
import keranqitiLixian from '@/assets/marks/keranqiti-lixian.png';
import yuntaiZaixian from '@/assets/marks/yuntai-zaixian.png';
import yuntaiLixian from '@/assets/marks/yuntai-lixian.png';
import videoMark from '@/assets/marks/video_mark.png';
import videoMarkHuise from '@/assets/marks/video_mark-huise.png';
import famenkaiguanZaixian from '@/assets/marks/famenkaiguan-zaixian.png';
import famenkaiguanLixian from '@/assets/marks/famenkaiguan-lixian.png';
import dtuZaixian from '@/assets/marks/DTU-zaixian.png';
import dtuLixian from '@/assets/marks/DTU-lixian.png';
import tiaotaqiZaixian from '@/assets/marks/tiaotaqi-zaixian.png';
import tiaoyaqiLixian from '@/assets/marks/tiaoyaqi-lixian.png';
import maidishiZaixian from '@/assets/marks/maidishi-zaixian.png';
import maidishiLixian from '@/assets/marks/maidishi-lixian.png';
import wurenjiZaixian from '@/assets/marks/wurenji-zaixian.png';
import wurenjiLixian from '@/assets/marks/wurenji-lixian.png';
import concentration from '@/assets/marks/concentration-alarm.png';
import gasStation from '@/assets/marks/perimeter-gasstation.png';
import canyinMark from '@/assets/marks/canyin-mark.png';
import thirdPartyConstruction from '@/assets/marks/perimeter-thirdPartyConstruction.png';
import fire from '@/assets/marks/perimeter-fire.png';
import police from '@/assets/marks/perimeter-police.png';
import hospital from '@/assets/marks/perimeter-hospital.png';
import government from '@/assets/marks/perimeter-goverment.png';
import residential from '@/assets/marks/perimeter-residential.png';
import subwayStation from '@/assets/marks/perimeter-subwaystation.png';
import denseArea from '@/assets/marks/perimeter-densearea.png';
import square from '@/assets/marks/perimeter-square.png';
import buchangqi from '@/assets/marks/pip_buchangqi.png';
import tiaoyaxiang from '@/assets/marks/pip_tiaoyaxiang.png';
import gateStation from '@/assets/marks/gate-station.png';
import jianceshebei from '@/assets/marks/jianceshebei-mark.png';
import wuzi from '@/assets/marks/wuzi_mark.png';
import wenhua from '@/assets/marks/wenhua_mark.png';
import yingji from '@/assets/marks/yingji_mark.png';
import xiaofangsuan from '@/assets/marks/xiaofangsuan.png';
import zhongdiandanwei from '@/assets/marks/zhongdiandanwei.png';
import xiaofangche from '@/assets/marks/xiaofangche.png';
import sashuiche from '@/assets/marks/sashuiche.png';
import xiaofangzhan from '@/assets/marks/xiaofangzhan.png';
import xiaofangdui from '@/assets/marks/xiaofangdui.png';
import jiuzaiwuzi from '@/assets/marks/jiuzaiwuzi.png';
import shiyingji from '@/assets/marks/shiyingji.png';
import zhongdiandizhi from '@/assets/marks/zhongdiandizhi.png';
//报警预警静态资源
import sijiWarning from '@/assets/marks/siji-warning.png';
import sanjiWarning from '@/assets/marks/sanji-warning.png';
import erjiWarning from '@/assets/marks/erji-warning.png';
import yijiWarning from '@/assets/marks/yiji-warning.png';

//报警总数的静态资源
import daichuzhi from '@/assets/marks/daichuzhi.png';
import chuzhizhong from '@/assets/marks/chuzhizhong.png';
import yiwancheng from '@/assets/marks/yiwancheng.png';
// 定义静态图片资源映射
const staticImageResources = {
  // 名称映射
  name: {
    '门站': {
      online: menzhanMark,
      offline: menzhanHuise
    },
    '调压站': {
      online: tiaoyazhanMark,
      offline: tiaoyazhanhuiseMark
    },
    '调峰储备站': {
      online: tiaofengchubeiMark,
      offline: tiaofengchubeiMark
    },
    '重点工商业户站': {
      online: shangyeMark,
      offline: gongyeMark
    },
    '第三方施工风险监测': {
      markerIcon: shigongMark
    },
    '抢修队': {
      markerIcon: qiangxiuduiMark
    },
    '泄漏监测': {
      online: concentrationMonitor,
      offline: concentrationMonitorLixian
    },
    '感知监测点': {
      online: perimeterRestaurant,
      offline: perimeterRestaurantLixian
    },
    '实时监控': {
      online: videoZaixian,
      offline: videoLixian
    },
    '第三方破坏监控': {
      online: videoZaixian,
      offline: videoLixian
    },
    '有效报警数': {
      markerIcon: paichu
    },
    '智能排除数': {
      markerIcon: paichu
    },
    '人工排除数': {
      markerIcon: paichu
    },
    '浓度报警': {
      markerIcon: concentration
    },
    '压力报警': {
      markerIcon: concentration
    },
    '阀门状态报警': {
      markerIcon: concentration
    },
    '破坏报警': {
      markerIcon: concentration
    },
    '阀门': {
      markerIcon: famen
    },
    '交通管制': {
      markerIcon: traffic
    },
    '加油加气站': { markerIcon: gasStation },
    '餐饮场所': { markerIcon: canyinMark },
    '第三方施工': { markerIcon: thirdPartyConstruction },
    '消防': { markerIcon: fire },
    '公安': { markerIcon: police },
    '医院': { markerIcon: hospital },
    '政府机关': { markerIcon: government },
    '学校': { markerIcon: school },
    '小区': { markerIcon: residential },
    '地铁站': { markerIcon: subwayStation },
    '人员密集区': { markerIcon: denseArea },
    '广场': { markerIcon: square },
    '补偿器': { markerIcon: buchangqi },
    '调压箱': { markerIcon: tiaoyaxiang },
    '自定义': { markerIcon: concentrationMonitor },
    '站点': { markerIcon: gateStation },
    'Box Camera': { markerIcon: videoMark },
    '设备': { markerIcon: jianceshebei },
    'video': { markerIcon: videoMark },
    '物资储备库': { markerIcon: wuzi },
    '公共文化场所': { markerIcon: wenhua },
    '应急避难场所': { markerIcon: yingji },
    '消防栓': { markerIcon: xiaofangsuan },
    '重点单位': { markerIcon: zhongdiandanwei },
    '消防车': { markerIcon: xiaofangche },
    '洒水车': { markerIcon: sashuiche },
    '消防站': { markerIcon: xiaofangzhan },
    '消防队': { markerIcon: xiaofangdui },
    '救灾物资储备库': { markerIcon: jiuzaiwuzi },
    '市应急联防救援站': { markerIcon: shiyingji },
    '重点地质灾害点': { markerIcon: zhongdiandizhi },
    '会展中心': { markerIcon: conventionCenter },
    '火车站': { markerIcon: trainStation },
    '汽车站': { markerIcon: busStation },
    '长途汽车站': { markerIcon: longDistanceBusStation },
    '森林防火重点街道': { markerIcon: forestFireStreet },
    '停车场': { markerIcon: parkingLot },
    '图书馆': { markerIcon: library },
    '文化宫': { markerIcon: culturalPalace },
    '物资点位': { markerIcon: materialPoint },
    '消防设备': { markerIcon: fireEquipment },
    '消防重点单位': { markerIcon: keyFireUnit },
    '摄像头': { markerIcon: camera },
    '救援队': { markerIcon: rescueTeam },
    '救援队伍': { markerIcon: rescueTeam },
    default: {
      online: concentrationMonitor,
      offline: concentrationMonitorLixian
    }
  },
  // 设备分类映射
  equipment: {
    '18': {
      online: gasWeishi,
      offline: gasWeishiHuise
    },
    '14': {
      online: keranqitiZaixian,
      offline: keranqitiLixian
    },
    '19': {
      online: keranqitiZaixian,
      offline: keranqitiLixian
    },
    '3': {
      online: yuntaiZaixian,
      offline: yuntaiLixian
    },
    '2': {
      online: yuntaiZaixian,
      offline: yuntaiLixian
    },
    '4': {
      online: videoMark,
      offline: videoMarkHuise
    },
    '16': {
      online: famenkaiguanZaixian,
      offline: famenkaiguanLixian
    },
    '7': {
      online: famenkaiguanZaixian,
      offline: famenkaiguanLixian
    },
    '20': {
      online: dtuZaixian,
      offline: dtuLixian
    },
    '11': {
      online: dtuZaixian,
      offline: dtuLixian
    },
    '12': {
      online: dtuZaixian,
      offline: dtuLixian
    },
    '13': {
      online: dtuZaixian,
      offline: dtuLixian
    },
    '23': {
      online: dtuZaixian,
      offline: dtuLixian
    },
    '24': {
      online: dtuZaixian,
      offline: dtuLixian
    },
    '26': {
      online: dtuZaixian,
      offline: dtuLixian
    },
    '21': {
      online: tiaotaqiZaixian,
      offline: tiaoyaqiLixian
    },
    '17': {
      online: tiaotaqiZaixian,
      offline: tiaoyaqiLixian
    },
    '10': {
      online: maidishiZaixian,
      offline: maidishiLixian
    },
    '22': {
      online: maidishiZaixian,
      offline: maidishiLixian
    },
    '25': {
      online: wurenjiZaixian,
      offline: wurenjiLixian
    },
    '30': {
      online: videoZaixian,
      offline: videoLixian
    }
  },
  // 场景类型映射
  scene: {
    '09': {
      online: keranqitiZaixian,
      offline: keranqitiLixian
    },
    '05': {
      online: menzhanMark,
      offline: menzhanHuise
    },
    '06': {
      online: tiaoyazhanMark,
      offline: tiaoyazhanhuiseMark
    },
    '07': tiaofengchubeiMark,
    '08': gongyeMark
  },
  //根据预警总数
  warningType: {
    '1': {
      markerIcon: sijiWarning
    },
    '2': {
      markerIcon: erjiWarning
    },
    '3': {
      markerIcon: sanjiWarning
    },
    '4': {
      markerIcon: yijiWarning
    }
  },

  //根据报警总数
  alarmType: {
    '1': {
      markerIcon: daichuzhi
    },
    '2': {
      markerIcon: chuzhizhong
    },
    '3': {
      markerIcon: yiwancheng
    }
  }
};

/**
 * 获取标记图片
 * @param {string} name - 图片名称/类型
 * @param {PointOptions} options - 包含状态和其他选项的对象
 * @returns {string} 对应的图片资源路径
 */
export const getMarkerImage = (name: string, options: PointOptions): string => {
  const { status, userType, sensorStatus, equipmentClassify, monitorScenceType, warningLevel } = options;
  // 确定当前状态
  const currentStatus = status === '1' || sensorStatus === '在线' ? 'online' : status === '0' || sensorStatus === '离线' ? 'offline' : null;

  // 1. 处理工商业用户特殊情况
  if (userType === '工业用户' || userType === '商业用户') {
    const nameConfig = staticImageResources.name['重点工商业户站'] || staticImageResources.name.default;
    return userType === '工业用户' ? nameConfig.offline : nameConfig.online;
  }

  // 2. 尝试从名称映射中获取但是有equipmentClassify字段的不能走这里
  if (name && staticImageResources.name[name] && !equipmentClassify) {
    const nameConfig = staticImageResources.name[name];

    // 如果有markerIcon直接使用
    if (nameConfig.markerIcon) {
      return nameConfig.markerIcon;
    }

    // 否则根据状态获取
    if (currentStatus && nameConfig[currentStatus]) {
      return nameConfig[currentStatus];
    }
  }

  // 3. 优先按设备分类匹配
  if (equipmentClassify && name !== '浓度报警' && staticImageResources.equipment[equipmentClassify]) {
    const statusKey = currentStatus || 'offline';
    // 本判断需要对应对领导所有为offline的代表是离线 离线的图标不展示
    if (name !== '相邻地下空间' && statusKey === 'offline') {
      console.log('statusKey', statusKey, options);
      return '';
    }
    const icon = staticImageResources.equipment[equipmentClassify][statusKey];
    if (icon) {
      return icon;
    }
  }

  // 4. 其次按场景类型匹配
  if (monitorScenceType && staticImageResources.scene[monitorScenceType]) {
    const sceneConfig = staticImageResources.scene[monitorScenceType];

    if (typeof sceneConfig === 'string') {
      return sceneConfig;
    } else if (currentStatus && sceneConfig[currentStatus]) {
      return sceneConfig[currentStatus];
    }
  }

  //5 处理预警报警级别
  if (warningLevel && staticImageResources.warningType[warningLevel]) {
    // 这里代表了预警和报警点位icon
    const warningTypeConfig = staticImageResources.warningType[warningLevel];
    if (warningTypeConfig.markerIcon) {
      return warningTypeConfig.markerIcon;
    }
  }
  //  6.报警总数点位icon
  if (status && staticImageResources.alarmType[status]) {
    const alarmTypeConfig = staticImageResources.alarmType[status];
    if (alarmTypeConfig.markerIcon) {
      return alarmTypeConfig.markerIcon;
    }
  }
  // 7. 最终回退到默认图标
  const defaultConfig = staticImageResources.name.default;
  const statusKey = currentStatus || 'offline';

  return defaultConfig[statusKey];
};

export default {
  getMarkerImage
};
